from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

SQLALCHEMY_DATABASE_URL = "sqlite:///./app_data.db"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
Base = declarative_base()  # 所有模型共享的基类
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)  # 会话工厂

def get_db():  # 用于获取数据库会话的依赖项
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()